package org.example.studentsystem_back.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.example.studentsystem_back.common.CommonResponse;
import org.example.studentsystem_back.domain.Students;
import org.example.studentsystem_back.dto.PageDTO;
import org.example.studentsystem_back.service.StudentsService;
import org.example.studentsystem_back.vo.dataCenterVo.StudentDataCenterVo.StudentDataCenterVo;
import org.example.studentsystem_back.vo.studentMangeVo.StudentsVo;
import org.example.studentsystem_back.vo.studentMangeVo.UpdateStudentVo;
import org.example.studentsystem_back.vo.userManageVo.PageStudentVo;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Valid
public class StudentsController {
    @Resource
    private StudentsService studentsService;

    //查询所有学生信息
    @GetMapping("/students/current")
    public CommonResponse<StudentsVo> getCurrentStudents(HttpServletRequest request){
        return studentsService.getCurrentStudents(request);
    }

    //根据uesrId查询学生信息
    @GetMapping("/students/{userId}")
    public CommonResponse<StudentsVo> getStudentByUserId(@PathVariable("userId") String userId){
        return studentsService.getStudentByUserId(userId);
    }

    //添加学生信息
    @PostMapping("/students")
    public CommonResponse<StudentsVo> addStudent(@RequestBody Students student){
        return studentsService.addStudent(student);
    }

    //根据uesrId修改学生信息
    @PutMapping("/students/{userId}")
    public CommonResponse<UpdateStudentVo> updateStudent(@PathVariable("userId") String userId, @RequestBody UpdateStudentVo updateStudentVo){
        return studentsService.updateStudent(userId,updateStudentVo);
    }

    //删除学生
    @DeleteMapping("/students/{id}")
    public CommonResponse<StudentsVo> deleteStudent(@PathVariable("id") String studentId){
        return studentsService.deleteStudent(studentId);
    }

    //分页查询学生信息
    @PostMapping("/students/page")
    public CommonResponse<PageStudentVo> getAllStudentsByPage(@RequestBody PageDTO pageDTO){
        return studentsService.getAllStudentsByPage(pageDTO);
    }

    //获取学生数据
    @GetMapping("/students/dataCenter")
    public CommonResponse<StudentDataCenterVo> getStudentDataCenter(){
        return studentsService.getStudentDataCenter();
    }
}
